package cn.detu.ln.controller;

import cn.detu.ln.entity.Warning;
import cn.detu.ln.service.WarningService;
import cn.detu.ln.utils.PageUtil;
import cn.detu.ln.utils.RestUtil;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("warning")
public class WarningController {
    @Autowired
    private WarningService warningService;
    @GetMapping("{url}")
    public RestUtil userGet(@PathVariable String url, Warning warning, PageUtil pageUtil, String search){
        switch (url){
            case "selectAll": return warningService.selectAll();
            case "selectOne": return warningService.select(warning.getStuNum());
            case "warningDelete":return warningService.warningDelete(warning.getWarningId());
            // 按学号查询
            case "queryWarningByStuNumPage":return warningService.queryWarningByStuNumPage(pageUtil.getCurrent(),
                    pageUtil.getRows(),search);
            // 按课程号查询
            case "queryWarningByCouIdPage":return warningService.queryWarningByCouIdPage(pageUtil.getCurrent(),
                    pageUtil.getRows(),search);
            // 按周数查询
            case "queryWarningByWeekPage":return warningService.queryWarningByWeekPage(pageUtil.getCurrent(),
                    pageUtil.getRows(),search);
        }

        return null;
    }
    @PostMapping("{url}")
    public RestUtil userPost(@PathVariable String url, Warning warning, String newPwd){
        switch (url){
            case "warningUpdate":return warningService.warningUpdate(warning);
            case "warningInsert":return warningService.warningInsert(warning);
        }
        return null;
    }
}
